package com.play.game.mydecoration.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.play.game.mydecoration.R;

import java.util.List;

/**
 * Created by 聪明一只哈 on 2018/5/20.
 * Time: 2018/5/20  10:42
 */

public class MyRecycleViewAdapter extends RecyclerView.Adapter<MyRecycleViewAdapter.MyViewHolder> {
    private Context context;
    private List<String> list;
    private final LayoutInflater inflater;

    public MyRecycleViewAdapter(Context context, List<String> list) {

        this.context = context;
        this.list = list;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {

        holder.item_tv.setText(list.get(position));

    }

    @Override
    public int getItemCount() {
        return list==null?0:list.size();
    }


    class MyViewHolder extends RecyclerView.ViewHolder{
        TextView item_tv;
        public MyViewHolder(View itemView) {
            super(itemView);
            item_tv=itemView.findViewById(R.id.item_tv);
        }
    }
}
